#ifndef NETPRINTER_H
#define NETPRINTER_H

#include <QObject>
#include <printerclient.h>

class NetPrinter : public PrinterClient
{
    Q_OBJECT
public:
    explicit NetPrinter(QObject *parent = nullptr);
    void setAddress(QString Ip, int Port) {
        ip = Ip;
        port = Port;
    }

    void sendData(const QByteArray& data);

signals:
    void dataSent();
    void errorOccurred(const QString& error);

private slots:
    void onConnected();
    void onBytesWritten(qint64 bytes);
    void onDisconnected();
    void onError(QAbstractSocket::SocketError error);
    void onTimeout();

private:
    void writeNextChunk();
    void cleanup();

    QString ip;
    int port;

    QTcpSocket* m_socket;
    QTimer* m_timeoutTimer;
    QByteArray m_data;
    qint64 m_bytesWritten = 0;

signals:
};

#endif // NETPRINTER_H
